{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">配置管理</div>
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                {volist name="$groupArray" id="vo"}
                <li class="{if $key==$group}layui-this{/if}"><a href="{:url('index',['group'=>$vo['name']])}">{$vo.title}</a></li>
                {/volist}
            </ul>
            <div class="layui-tab-content">
                <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="barTool">
    {{# if(d.type=='radio' || d.type=='select'){ }}
    <a href='javascript:;' class="layui-btn layui-btn-normal layui-btn-xs copy" title="复制调用代码" data-clipboard-text="{literal}键：{:config('{{d.name}}')} 值：{:config('{{d.name}}_text')}{/literal}"><i class="layui-icon layui-icon-fonts-code"></i></a>
    {{# } else if(d.type=='checkbox' || d.type=='array' || d.type=='images' || d.type=='files'){ }}
    <a href='javascript:;' class="layui-btn layui-btn-normal layui-btn-xs copy" title="复制调用代码" data-clipboard-text="{literal}{volist name=&quot;:config('{{d.name}}')&quot; id='vo'}  键：{$key}  值：{$vo} <br> {/volist}{/literal}"><i class="layui-icon layui-icon-fonts-code"></i></a>
    {{# } else { }}
    <a href='javascript:;' class="layui-btn layui-btn-normal layui-btn-xs copy" title="复制调用代码" data-clipboard-text="{literal}{:config('{{d.name}}')}{/literal}"><i class="layui-icon layui-icon-fonts-code"></i></a>
    {{# } }}
    <a data-open='{:url("edit")}?id={{ d.id }}' title="编辑" class="layui-btn layui-btn-xs"><i class="layui-icon layui-icon-edit"></i></a>
    <a href='{:url("del")}?ids={{ d.id }}' class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del" title="删除"><i class="layui-icon layui-icon-delete"></i></a>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="status" data-href="{:url('multi')}?id={{d.id}}&param=status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>

{/block}
{block name="script"}
<script>
    layui.use(['yznTable','clipboard'], function() {
        var table = layui.yznTable,
            $ = layui.$,
            form = layui.form,
            clipboard =  layui.clipboard;

        var init = {
            table_elem: '#currentTable',
            add_url: "{:url('add')}",
            modify_url:'{:url("multi")}',
        };

        table.render({
            init: init,
            id:'currentTable',
            elem: '#currentTable',
            toolbar: ['refresh','add'],
            url: '{:url("index",["group"=>$group])}',
            search:false,
            cols: [
                [
                    {field: 'id', title: 'ID', width: 80,  sort: true, fixed: true, align:"center"},
                    {field: 'sort', width: 80, title: '排序',edit: 'text',fixed: true, align:"center"},
                    { field: 'name',align: "left", width: 220, title: '名称' },
                    { field: 'title',align: "left", width: 300, title: '标题' },
                    { field: 'type', width: 150, title: '类型' },
                    { field: 'value',  title: '配置值' },
                    { field: 'update_time', width: 200, title: '更新时间', align:"center"},
                    { field: 'status', title: '状态', width: 100, templet: '#switchTpl', unresize: true, align:"center"},
                    { fixed: 'right', width: 200, title: '操作', toolbar: '#barTool', align:"center"}
                ]
            ],
            page: {}
        });

        var clipboard = new clipboard('.copy');
        clipboard.on('success', function(e) {
            layer.msg("复制成功",{ icon: 1});
        });
        clipboard.on('error', function(e) {
            layer.msg("复制失败！请手动调用",{ icon: 2});
        });
    });
</script>
{/block}
